import { _decorator, Component, Node, director, RigidBody2D, ERigidBody2DType, Vec3, Label } from 'cc';
import { pushBoxTs } from '../pushBoxTs';
const { ccclass } = _decorator;

@ccclass('GlobalAttribute')
export class GlobalAttribute extends Component {
    private static instance: GlobalAttribute;
    // 可以被全局访问和修改的属性或方法
    public nodeArr: Array<Node> = [];
    public moveDirection: 'x' | 'y' | null = null;
    //是否为操作状态
    public operatingState: Boolean = false;

    public thisnode: Node = null;
    public otherArr: Array<Node> = [];

    //检测是否结束游戏
    public gameOver: Boolean = false;

    // 公共构造函数
    constructor() {
        super();
        GlobalAttribute.instance = this;
        this.initPosArr = [];
    }

    // 获取唯一实例的方法
    public static getInstance(): GlobalAttribute {
        if (!GlobalAttribute.instance) {
            // 这里创建一个新的节点并将其添加到场景中，以便使用Component的功能
            const globalNode = new Node('GlobalAttributeNode');
            director.getScene()?.addChild(globalNode);
            GlobalAttribute.instance = globalNode.addComponent(GlobalAttribute);
        }
        return GlobalAttribute.instance;
    }

    public get getNodeArrPos() {
        return this.nodeArr;
    }

    public set addNode(node: Node) {
        if (!this.nodeArr.some(e => e === node)) {

            this.nodeArr.push(node);
        }
        
    }
    public clearNodeArr() {
        if (this.nodeArr.length > 0) {
            this.nodeArr = [];
        }
    }
   

    public get getOperatingState() {
        return this.operatingState;
    }
    public set setOperatingState(value) {
        this.operatingState = value;
        // console.log(this.operatingState);

    }

    public get getthisnode() {
        return this.thisnode;
    }
    public set setthisnode(value) {
        this.thisnode = value;
    }

    public get getOtherArr() {
        return this.otherArr;
    }
    public set setOtherArr(value) {
        if (!this.otherArr.some(e => e === value)) {
            this.otherArr.push(value);
            // console.log(this.otherArr);

        }
    }
    public clearotherarr() {
        this.otherArr = [];
    }


}
